﻿using System;
using Netkk.Common.Interfaces.Repositories;
using Netkk.Common.Interfaces.Services;
using Netkk.Common.Models;
using System.Collections.Generic;

namespace Netkk.Library.Services
{
    public class RegistrationService : IRegistrationService
    {
        private readonly IRegistrationRepository repository;

        public RegistrationService(IRegistrationRepository repository)
        {
            this.repository = repository;
        }

        //protected bool ValidateRegistration(Registration registration)
        //{
        //    if (String.IsNullOrEmpty(registration.FirstName))
        //    {
        //        validationDictionary.AddError("FirstName", "Bitte eines Vornamen eingeben.");
        //    }
        //    if (String.IsNullOrEmpty(registration.LastName))
        //    {
        //        validationDictionary.AddError("LastName", "Bitte eines Nachnamen eingeben.");
        //    }
        //    if (String.IsNullOrEmpty(registration.Email))
        //    {
        //        validationDictionary.AddError("Email", "Bitte eine E-Mail eingeben.");
        //    }
        //    if (!registration.Email.IsValidEmail())
        //    {
        //        validationDictionary.AddError("Email", "Bitte eine gültige E-Mail eingeben.");
        //    }

        //    return validationDictionary.IsValid;
        //}

        public IEnumerable<Registration> SeletAllRegistrations()
        {
            return repository.Select();
        }

        public Registration LoadRegistrationsById(Guid id)
        {
            throw new NotImplementedException();
        }

        public void DeleteRegistration(Registration registration)
        {
            repository.Delete(registration);
        }

        public bool SaveRegistration(Registration registration)
        {
            // Database logic
            try
            {
                repository.Save(registration);
            }
            catch
            {
                return false;
            }
            return true;
        }
    }

}
